﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Products.aspx.cs" Inherits="MemberMgr.Website.Admin.Products" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        var GridCommand = function(command, record, rowIndex) {
            if (command == "Edit") {
                Ext.net.DirectMethods.editProduct(record.id);
            } else if (command = "Delete") {
                Ext.Msg.confirm("删除商品", "确定删除当前商品吗？", function(btn) {
                    if (btn == "yes") {
                        Ext.net.DirectMethods.deleteProduct(record.id);
                    }
                });
            }
        }
    </script>
</head>
<body>
    <form id="productForm" runat="server">
    <ext:ResourceManager runat="server" Locale="zh-CN" />
    <ext:Store ID="storeProduct" runat="server" OnRefreshData="storeProduct_RefreshData">
        <Reader>
            <ext:JsonReader IDProperty="ID">
                <Fields>
                    <ext:RecordField Name="PRODUCTNAME" />
                    <ext:RecordField Name="PRODUCTTYPE" />
                    <ext:RecordField Name="MAKER" />
                    <ext:RecordField Name="PRICE" Type="Float" />
                    <ext:RecordField Name="COMMENT" />
                    <ext:RecordField Name="PRODUCTSUM" Type="Float" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="border">
        <Items>
            <ext:FormPanel ID="searchPanel" runat="server" Region="North" Title="查询条件" Padding="5"
                Height="100" Frame="true" Margins="5 5 5 5" Layout="Table" Icon="Magnifier">
                <Items>
                    <ext:TableLayout ID="tblLayout" runat="server" Columns="4" LabelWidth="70" LabelAlign="Right">
                        <Cells>
                            <ext:Cell ColSpan="4">
                                <ext:TextField ID="txtSearchName" runat="server" Text="" FieldLabel="商品名称">
                                </ext:TextField>
                            </ext:Cell>
                        </Cells>
                    </ext:TableLayout>
                </Items>
                <Buttons>
                    <ext:Button ID="btnSearch" Type="Button" runat="server" Text=" 查 询 ">
                        <DirectEvents>
                            <Click OnEvent="btnSearch_Click" DisableCaching="true">
                                <EventMask ShowMask="true" Msg="正在查询，请稍后..." />
                            </Click>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:FormPanel>
            <ext:GridPanel ID="gpProducts" runat="server" StoreID="storeProduct" Title="商品信息"
                AutoExpandColumn="Comment" Margins="0 5 5 5" Region="Center" Frame="true">
                <TopBar>
                    <ext:Toolbar ID="tblGrid" runat="server">
                        <Items>
                            <ext:Button ID="btnAdd" runat="server" Text="添加商品" Icon="Add">
                                <Listeners>
                                    <Click Handler="#{panelDetail}.getForm().reset();#{winDetail}.show();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="cmGrid" runat="server">
                    <Columns>
                        <ext:CommandColumn Width="60">
                            <Commands>
                                <ext:GridCommand Icon="Delete" CommandName="Delete">
                                    <ToolTip Text="删除" />
                                </ext:GridCommand>
                                <ext:CommandSeparator />
                                <ext:GridCommand Icon="NoteEdit" CommandName="Edit">
                                    <ToolTip Text="编辑" />
                                </ext:GridCommand>
                            </Commands>
                        </ext:CommandColumn>
                        <ext:RowNumbererColumn />
                        <ext:Column Header="商品名称" Width="190" DataIndex="PRODUCTNAME">
                        </ext:Column>
                        <ext:Column Header="商品类型" Width="190" DataIndex="PRODUCTTYPE">
                        </ext:Column>
                        <ext:Column Header="制造商" Width="190" DataIndex="MAKER">
                        </ext:Column>
                        <ext:NumberColumn Header="价格" Width="190" DataIndex="PRICE">
                        </ext:NumberColumn>
                        <ext:NumberColumn Header="数量" Width="190" DataIndex="PRODUCTSUM">
                        </ext:NumberColumn>
                        <ext:Column ColumnID="Comment" Header="备注" Width="190" DataIndex="COMMENT">
                        </ext:Column>
                        
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="rowSelModeNote" runat="server" />
                </SelectionModel>
                <LoadMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolbar ID="pageTool" runat="server" PageSize="10" StoreID="storeProduct" />
                </BottomBar>
                <Listeners>
                    <Command Fn="GridCommand" />
                </Listeners>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    <ext:Window ID="winDetail" runat="server" Icon="PageWhiteText" Title="详细信息" CloseAction="Hide"
        Frame="true" Modal="true" Hidden="true" Width="300" Height="300" Resizable="false">
        <Items>
            <ext:FormPanel ID="panelDetail" runat="server" LabelWidth="60" AutoWidth="true" Padding="5"
                Frame="true">
                <Items>
                    <ext:Hidden ID="txtID" runat="server" DataIndex="Id">
                    </ext:Hidden>
                    <ext:TextField ID="txtProductName" runat="server" FieldLabel="商品名称" DataIndex="Productname">
                    </ext:TextField>
                    <ext:TextField ID="txtProductType" runat="server" FieldLabel="商品类型" DataIndex="Producttype">
                    </ext:TextField>
                    <ext:TextField ID="txtMaker" runat="server" FieldLabel="制造商" DataIndex="Maker">
                    </ext:TextField>
                    <ext:NumberField ID="txtPrice" runat="server" FieldLabel="价格" DataIndex="Price">
                    </ext:NumberField>
                    <ext:TextField ID="txtComment" runat="server" FieldLabel="备注" Width="100" DataIndex="Comment">
                    </ext:TextField>
                </Items>
            </ext:FormPanel>
        </Items>
        <Buttons>
            <ext:Button ID="btnSave" runat="server" Text=" 保 存 " Icon="DatabaseSave">
                <DirectEvents>
                    <Click OnEvent="btnSave_Click">
                        <EventMask ShowMask="true" Msg="正在保存数据，请稍后..." />
                    </Click>
                </DirectEvents>
            </ext:Button>
            <ext:Button ID="btnClose" runat="server" Text=" 关 闭 " Icon="Decline" OnClientClick="#{winDetail}.hide()" />
        </Buttons>
    </ext:Window>
    </form>
</body>
</html>
